// Copyright (c) ZeroC, Inc. All rights reserved.

using System.Collections.Generic;
using System.Linq;
using Test;

namespace ZeroC.Ice.Test.DictMapping
{
    public class Twoways
    {
        internal static void Run(IMyClassPrx p)
        {
            {
                var i = new Dictionary<int, int>
                {
                    [0] = 1,
                    [1] = 0
                };

                (Dictionary<int, int> r, Dictionary<int, int> o) = p.OpNV(i);

                TestHelper.Assert(i.DictionaryEquals(o));
                TestHelper.Assert(i.DictionaryEquals(r));
            }

            {
                var i = new Dictionary<string, string>
                {
                    ["a"] = "b",
                    ["b"] = "a"
                };

                (Dictionary<string, string> r, Dictionary<string, string> o) = p.OpNR(i);

                TestHelper.Assert(i.DictionaryEquals(o));
                TestHelper.Assert(i.DictionaryEquals(r));
            }

            {
                var i = new Dictionary<string, Dictionary<int, int>>();
                var id = new Dictionary<int, int>
                {
                    [0] = 1,
                    [1] = 0
                };
                i["a"] = id;
                i["b"] = id;

                (Dictionary<string, Dictionary<int, int>> r, Dictionary<string, Dictionary<int, int>> o) = p.OpNDV(i);

                foreach (string key in i.Keys)
                {
                    TestHelper.Assert(i[key].DictionaryEquals(o[key]));
                    TestHelper.Assert(i[key].DictionaryEquals(r[key]));
                }
            }

            {
                var i = new Dictionary<string, Dictionary<string, string>>();
                var id = new Dictionary<string, string>
                {
                    ["a"] = "b",
                    ["b"] = "a"
                };
                i["a"] = id;
                i["b"] = id;

                (Dictionary<string, Dictionary<string, string>> r,
                 Dictionary<string, Dictionary<string, string>> o) = p.OpNDR(i);

                foreach (string key in i.Keys)
                {
                    TestHelper.Assert(i[key].DictionaryEquals(o[key]));
                    TestHelper.Assert(i[key].DictionaryEquals(r[key]));
                }
            }

            {
                int[] ii = new int[] { 1, 2 };
                var i = new Dictionary<string, int[]>
                {
                    ["a"] = ii,
                    ["b"] = ii
                };

                (Dictionary<string, int[]> r, Dictionary<string, int[]> o) = p.OpNDAIS(i);

                foreach (string key in i.Keys)
                {
                    TestHelper.Assert(i[key].SequenceEqual(o[key]));
                    TestHelper.Assert(i[key].SequenceEqual(r[key]));
                }
            }

            {
                var ii = new List<int>
                {
                    1,
                    2
                };
                var i = new Dictionary<string, List<int>>
                {
                    ["a"] = ii,
                    ["b"] = ii
                };

                (Dictionary<string, List<int>> r, Dictionary<string, List<int>> o) = p.OpNDGIS(i);

                foreach (string key in i.Keys)
                {
                    TestHelper.Assert(i[key].SequenceEqual(o[key]));
                    TestHelper.Assert(i[key].SequenceEqual(r[key]));
                }
            }

            {
                string[] ii = new string[] { "a", "b" };
                var i = new Dictionary<string, string[]>
                {
                    ["a"] = ii,
                    ["b"] = ii
                };

                (Dictionary<string, string[]> r, Dictionary<string, string[]> o) = p.OpNDASS(i);

                foreach (string key in i.Keys)
                {
                    TestHelper.Assert(i[key].SequenceEqual(o[key]));
                    TestHelper.Assert(i[key].SequenceEqual(r[key]));
                }
            }

            {
                var ii = new List<string>
                {
                    "a",
                    "b"
                };
                var i = new Dictionary<string, List<string>>
                {
                    ["a"] = ii,
                    ["b"] = ii
                };

                (Dictionary<string, List<string>> r, Dictionary<string, List<string>> o) = p.OpNDGSS(i);

                foreach (string key in i.Keys)
                {
                    TestHelper.Assert(i[key].SequenceEqual(o[key]));
                    TestHelper.Assert(i[key].SequenceEqual(r[key]));
                }
            }
        }
    }
}
